//
//  JiebangCell.m
//  SSC
//
//  Created by 红沙尘 on 17/7/11.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "JiebangCell.h"

@interface JiebangCell ()
{
    NSDictionary *_dataDict;
}


@end

@implementation JiebangCell
{
    __weak IBOutlet UILabel *labelA;
    __weak IBOutlet UILabel *labelB;
    __weak IBOutlet UILabel *labelC;
    __weak IBOutlet UILabel *labelD;
    
    __weak IBOutlet UIView *bg;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
    bg.layer.borderWidth = LineHeight;
    bg.layer.borderColor = COLOR_CCCCCC.CGColor;
}

- (void)loadWithDict:(NSDictionary *)dict {
    
    _dataDict = [dict copy];
    
    labelA.text = [NSString stringWithFormat:@"银行: %@",dict[@"banks"]];
    labelB.text = [NSString stringWithFormat:@"开户行: %@",dict[@"bankname"]];
    labelC.text = [NSString stringWithFormat:@"银行卡号: %@",dict[@"bankcard"]];
    labelD.text = [NSString stringWithFormat:@"账户名: %@",dict[@"username"]];
}

- (IBAction)jiebang {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
                                                                             message:@"是否解绑该银行卡"
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"解绑"
                                                        style:UIAlertActionStyleDestructive
                                                      handler:^(UIAlertAction * _Nonnull action)
                                {
                                    WeakSelf
                                    [weakSelf jiebangRequest];
                                }]];
    
    [[self viewController] presentViewController:alertController animated:YES completion:nil];
}

- (void)jiebangRequest {
    
    if ([self.jDelegate respondsToSelector:@selector(jiebangWithDict:)]) {
        [self.jDelegate jiebangWithDict:_dataDict];
    }    
}

- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    
    return nil;
}

@end
